#ifndef _EVENTS_DEF_H_
#define _EVENTS_DEF_H_

#include "ievent.h"
#include "bike.pb.h"
#include <string>

class MobileCodeReqEv : public iEvent {
public:
	MobileCodeReqEv(const std::string& mobile) :iEvent(EEVENTID_GET_MOBLIE_CODE_REQ, iEvent::generateSeqNo())
	{
		msg_.set_mobile(mobile);
		ceshi = getReasonByErrorCode(ERRC_SUCCESS);
	}

	const std::string& get_mobile() { return msg_.mobile(); }

	virtual std::ostream& dump(std::ostream& out) const;
	virtual i32 ByteSize() { return msg_.ByteSize(); }
	virtual bool SerializeToArray(char* buf, int len) { return msg_.SerializeToArray(buf, len); }

private:
	tutorial::mobile_request msg_;
	const char* ceshi;
};

class MobileCodeRspEv :public iEvent {
public:
	MobileCodeRspEv(i32 code, i32 icode) :iEvent(EEVENTID_GET_MOBLIE_CODE_RSP, iEvent::generateSeqNo()) {
		msg_.set_code(code);
		msg_.set_icode(icode);
		msg_.set_data(getReasonByErrorCode(code));
	}

	const i32 get_code() { return msg_.code(); }
	const i32 get_icode() { return msg_.icode(); }
	const std::string& get_data() { return msg_.data(); }

	virtual std::ostream& dump(std::ostream& out)const;
	virtual i32 ByteSize() { return msg_.ByteSize(); }
	virtual bool SerializeToArray(char* buf, int len) { return msg_.SerializeToArray(buf, len); }
private:
	tutorial::mobile_response msg_;
};

// 退出响应的事件
class ExitRspEv :public iEvent {
public:
	ExitRspEv() :iEvent(EEVENTID_EXIT_RSP, iEvent::generateSeqNo()) { }
	~ExitRspEv() { }
};

// 登录请求事件
class LoginReqEv :public iEvent {
public:
	LoginReqEv(const std::string& mobile, i32 code) :iEvent(EEVENTID_LOGIN_REQ, iEvent::generateSeqNo()) {
		msg_.set_mobile(mobile);
		msg_.set_icode(code);
	}
	const std::string& get_mobile() { return msg_.mobile(); }
	const i32 get_code() { return msg_.icode(); }

	virtual std::ostream& dump(std::ostream& out)const;
	virtual i32 ByteSize() { return msg_.ByteSize(); }
	virtual bool SerializeToArray(char* buf, int len) { return msg_.SerializeToArray(buf, len); }


private:
	tutorial::login_request msg_;    // 登录请求
};

// 登录响应事件
class LoginRspEv :public iEvent {
public:
	LoginRspEv(i32 icode) :iEvent(EEVENTID_LOGIN_RSP, iEvent::generateSeqNo()) {
		msg_.set_code(icode);
		msg_.set_desc(getReasonByErrorCode(icode));
	}
	const i32 get_icode() { return msg_.code(); }

	virtual std::ostream& dump(std::ostream& out)const;
	virtual i32 ByteSize() { return msg_.ByteSize(); }
	virtual bool SerializeToArray(char* buf, int len) {
		//std::cout << "into LoginRspEv-->SerializeToArray." << std::endl;
		return msg_.SerializeToArray(buf, len);
		/*if (!SerializeToArray(buf, len)) {
			std::cout << "false." << std::endl;
			sleep(20);
			return false;
		}
		return true;*/
	}

private:
	tutorial::login_response msg_;
};

//充值请求事件
class RechargeReqEv :public iEvent {
public:
	RechargeReqEv(const std::string& mobile, i32 money) :iEvent(EEVENTID_RECHARGE_REQ, iEvent::generateSeqNo()) {
		msg_.set_mobile(mobile);
		msg_.set_amount(money);
	}

	const std::string& get_mobile() { return msg_.mobile(); }
	const i32 get_amount() { return msg_.amount(); }

	virtual std::ostream& dump(std::ostream& out)const;
	virtual i32 ByteSize() { return msg_.ByteSize(); }
	virtual bool SerializeToArray(char* buf, int len) { return msg_.SerializeToArray(buf, len); }

private:
	tutorial::recharge_request msg_;    // 充值请求

};

//充值响应事件
class RechargeRspEv :public iEvent {
public:
	RechargeRspEv(i32 icode, i32 balance) :iEvent(EEVENTID_RECHARGE_RSP, iEvent::generateSeqNo()) {
		msg_.set_code(icode);
		msg_.set_desc(getReasonByErrorCode(icode));
		msg_.set_balance(balance);
	}
	const i32 get_icode() { return msg_.code(); }
	const i32 get_balance() { return msg_.balance(); }

	virtual std::ostream& dump(std::ostream& out)const;
	virtual i32 ByteSize() { return msg_.ByteSize(); }
	virtual bool SerializeToArray(char* buf, int len) {
		return msg_.SerializeToArray(buf, len);

	}

private:
	tutorial::recharge_response msg_;
};


#endif // !_EVENTS_DEF_H_

